apiVersion: v1
kind: Service
metadata:
  name: {{ .Values.name }}
spec:
  selector:
    app: {{ .Values.name }}
  type: ClusterIP
  ports:
    - name: http
      port: 8080
      targetPort: 8080
      protocol: TCP
    - name: grpc
      port: 9090
      targetPort: 9090
      protocol: TCP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.name }}
  labels:
    app: {{ .Values.name }}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: {{ .Values.name }}
  template:
    metadata:
      labels:
        app: {{ .Values.name }}
      annotations:
        rollme: {{ randAlphaNum 5 | quote }}
    spec:
      containers:
        - name: {{ .Values.name }}
          image: ghcr.io/al-bina-co-hahaton-2024/{{ .Values.name }}:{{ .Values.image.tag }}
          imagePullPolicy: Always
          ports:
            - containerPort: 8080
              protocol: TCP
            - containerPort: 9090
              protocol: TCP
          env:
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            
            {{- range .Values.secrets }}
            - name: {{ .env | upper }}
              valueFrom:
                secretKeyRef:
                    name: {{ .name }}
                    key: {{ .key }}
            {{- end }}

          envFrom:
            - configMapRef:
                name: common-service-envs
          readinessProbe:
            httpGet:
              path: /actuator/health
              port: 8080
            initialDelaySeconds: 10
            periodSeconds: 2

      imagePullSecrets:
        - name: dpr-secret
